/*
 * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
 * http://www.gnu.org/licenses/gpl-3.0.html
 */

#ifndef CODEBLOCKS_APP_H
#define CODEBLOCKS_APP_H

#include <wx/wxprec.h>

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#if !defined(WX_PRECOMP)
    #include <wx/wx.h>
    #include <wx/intl.h>
    #include <wx/laywin.h>
    #include <wx/image.h>
    #include <wx/filename.h>
    #include <wx/hashmap.h>
    #include <wx/docview.h> // recent files history 最近的文件历史记录
#endif

#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
    #include "resources/icons/app.xpm"
#endif

#include <wx/taskbar.h>
#include <wx/splash.h>
#include <wx/snglinst.h>
#include "manager.h"
#include "main.h"
/** CodeBlock SDK 主页
 * 开放源码,跨平台,免费C,C++和FORTRAN IDE.Code::Blocks中的大多数特性都是通过各种插件实现的.
 * 下面是跳转到sdk的一些有用的地方.
 * 插件接口(有向图插件):
 * digraph Plugins
 * {
 *   node [fontname="FreeSans", fontsize="10", shape=record];
 *   rankdir="LR";
 *   a [label="cbPlugin", URL="\ref cbPlugin", tooltip="Base class for all Code::Blocks plugins.", height=0.2];
 *
 *   b [label="cbCodeCompletionPlugin", URL="\ref cbCodeCompletionPlugin", tooltip="Base class for code-completion plugins.",  height=0.2];
 *   a -> b [dir="back", color="MidnightBlue"];
 *   c [label="cbCompilerPlugin",       URL="\ref cbCompilerPlugin",       tooltip="Base class for compiler plugins.",         height=0.2];
 *   a -> c [dir="back", color="MidnightBlue"];
 *   d [label="cbDebuggerPlugin",       URL="\ref cbDebuggerPlugin",       tooltip="Base class for debugger plugins.",         height=0.2];
 *   a -> d [dir="back", color="MidnightBlue"];
 *   e [label="cbMimePlugin",           URL="\ref cbMimePlugin",           tooltip="Base class for mime plugins.",             height=0.2];
 *   a -> e [dir="back", color="MidnightBlue"];
 *   f [label="cbSmartIndentPlugin",    URL="\ref cbSmartIndentPlugin",    tooltip="Base class for automatic indent plugins.", height=0.2];
 *   a -> f [dir="back", color="MidnightBlue"];
 *   g [label="cbToolPlugin",           URL="\ref cbToolPlugin",           tooltip="Base class for tool plugins.",             height=0.2];
 *   a -> g [dir="back", color="MidnightBlue"];
 *   h [label="cbWizardPlugin",         URL="\ref cbWizardPlugin",         tooltip="Base class for wizard plugins.",           height=0.2];
 *   a -> h [dir="back", color="MidnightBlue"];
 * }
 *
 * 管理器(有向图管理器):
 * digraph Managers
 * {
 *   node [fontname="FreeSans", fontsize="10", shape=record];
 *   rankdir="LR";
 *   a [label="Mgr\<MgrT\>", URL="\ref Mgr", tooltip="管理器的单一基础.", height=0.2];
 *   b [label="CCManager",        URL="\ref CCManager",        tooltip="管理访问和共享代码自动补全功能.",  height=0.2];
 *   a -> b [dir="back", color="MidnightBlue"];
 *   c [label="ColourManager",    URL="\ref ColourManager",    tooltip="管理可配置的颜色设置.",                 height=0.2];
 *   a -> c [dir="back", color="MidnightBlue"];
 *   d [label="ConfigManager",    URL="\ref ConfigManager",    tooltip="统一设置存储.",                             height=0.2];
 *   a -> d [dir="back", color="MidnightBlue"];
 *   e [label="DebuggerManager",  URL="\ref DebuggerManager",  tooltip="处理调试器插件.",                             height=0.2];
 *   a -> e [dir="back", color="MidnightBlue"];
 *   f [label="EditorManager",    URL="\ref EditorManager",    tooltip="处理打开的编辑器.",                                 height=0.2];
 *   a -> f [dir="back", color="MidnightBlue"];
 *   g [label="FileManager",      URL="\ref FileManager",      tooltip="管理低级文件访问.",                        height=0.2];
 *   a -> g [dir="back", color="MidnightBlue"];
 *   h [label="LogManager",       URL="\ref LogManager",       tooltip="访问共享日志功能.",                      height=0.2];
 *   a -> h [dir="back", color="MidnightBlue"];
 *   i [label="MacrosManager",    URL="\ref MacrosManager",    tooltip="处理文本替换宏.",                      height=0.2];
 *   a -> i [dir="back", color="MidnightBlue"];
 *   j [label="PluginManager",    URL="\ref PluginManager",    tooltip="管理已安装的插件.",                            height=0.2];
 *   a -> j [dir="back", color="MidnightBlue"];
 *   k [label="ProjectManager",   URL="\ref ProjectManager",   tooltip="管理项目和工作区.",                   height=0.2];
 *   a -> k [dir="back", color="MidnightBlue"];
 *   l [label="ScriptingManager", URL="\ref ScriptingManager", tooltip="处理脚本注册和使用.",                height=0.2];
 *   a -> l [dir="back", color="MidnightBlue"];
 * }
 *
 * 请参考在维基中<a href="http://wiki.codeblocks.org/index.php?title=Developer_documentation">开发者文档</a>
 */

/*启动屏幕类*/
class cbSplashScreen;

class CodeBlocksApp : public wxApp
{
    public:
        virtual bool OnInit();
        virtual int OnExit();
        virtual int OnRun();
        wxString GetAppPath() const;
        //命令行解释
        int ParseCmdLine(MainFrame* handlerFrame, const wxString& CmdLine = wxEmptyString);
        //应用激活事件
        void OnAppActivate(wxActivateEvent& event);
        //被命令行解释器解释事件
        bool OnCmdLineParsed(wxCmdLineParser& parser);
        //致命异常
        void OnFatalException();
        void LoadDelayedFiles(MainFrame* frame);
        // command line or DDE (if available) files 命令行或DDE(如果DDE可用)文件
        // [DDE是一种在操作系统层面上软件间相互调用机制如cilent-server机制]
        void SetAutoFile(wxString& file);
        // method to set m_AutoFile 设置m_AutoFile变量的方法
#ifdef __WXMAC__
        // in response of an open-document apple event
        //作为对苹果机[MAC]打开文件事件的回应
        virtual void         MacOpenFile(const wxString &fileName) ;
        // in response of a print-document apple event
        //作为对苹果机[MAC]打印文件事件的回应
        virtual void         MacPrintFile(const wxString &fileName) ;
#endif
        //添加文件到被延迟打开队列
        void AddFileToOpenDelayed(const wxString& filename);
    protected:
        //批构建完成除法事件参数类型是CodeBlocksEvent
        void OnBatchBuildDone(CodeBlocksEvent& event);
        void OnTBIconLeftDown(wxTaskBarIconEvent& event);
        //载入配置
        bool LoadConfig();
        //初始化调试控制台
        void InitDebugConsole();
        //初始化异常句柄[处理函数]
        void InitExceptionHandler();
        //初始化XRC资源填充[XRC资源是指菜单/图片/配置文件等]
        bool InitXRCStuff();
        //初始化窗口框架[返回MainFrame类型指针]
        MainFrame* InitFrame();
        //检测版本
        void CheckVersion();
        //本地化设置语言之类
        void InitLocale();
        //批任务
        int BatchJob();
        wxLocale m_locale;
        // locale we'll be using 我们将使用的区域[本地化]设置
        //延时去打开的文件字符串数组
        wxArrayString m_DelayedFilesToOpen;
    private:
        //个性化设置
        void SetupPersonality(const wxString& personality);
        //在--prefix[一般指应用程序的安装目录]开关中指定路径
        wxString m_Prefix; // directory specified in --prefix switch
        //在--user-data-dir[用户数据目录]开关中指定路径
        wxString m_UserDataDir; // directory specified in --user-data-dir switch
        //批处理目标
        wxString m_BatchTarget;
        //脚本[管理脚本?]
        wxString m_Script;
        wxString m_AutoFile; // --file foo.cpp[:line]
        //批构建对话框
        wxScrollingDialog* m_pBatchBuildDialog;
        //主框架窗口
        MainFrame* m_Frame;
        //单实例检测器
        wxSingleInstanceChecker* m_pSingleInstance;
        //内部动作状态变量
        bool m_Batch;//批处理状态
        bool m_BatchNotify;//批处理通知
        bool m_BatchWindowAutoClose; // default: true 批处理窗口自动关闭,缺省为真(true)
        bool m_Build;//构建
        bool m_ReBuild;//重新构建
        bool m_Clean;//清理临时文件[构建/编译是生成的]
        bool m_HasProject;//有项目
        bool m_HasWorkSpace;//有工作空间
        bool m_Splash; // splash screen enabled 启动窗口可用
        bool m_HasDebugLog; // display debug log 显示调试日志
        bool m_CrashHandler; // crash handler enabled 已启用崩溃处理程序
        bool m_SafeMode; // all plugins disabled 安全模式[所有插件不可用]
        //初始关联
        void InitAssociations();

        bool m_DDE;
        // DDE enabled?
        // DDE是否可用
#ifdef __WXMSW__
        bool m_Assocs; // associations check enabled 关联检查已启用
#endif
        //批处理返回码
        int m_BatchExitCode;
        //声明事件处理表
        DECLARE_EVENT_TABLE()
};

DECLARE_APP(CodeBlocksApp);

#endif // CODEBLOCKS_APP_H
